<template>
  <div class="searchlist">
    <van-sticky>
      <div class="top">
        <div
          class="iconfont icon-arrowRight-copy-copy"
          @click="$router.go(-1)"
        ></div>
        <div class="ipt">
          <input type="text" @click="$router.go(-1)" v-model="key" />
          <div class="iconfont icon-sousuo"></div>
        </div>
      </div>
    </van-sticky>

    <div class="item">
      <div
        class="items"
        v-for="item in keyword"
        :key="item.r.id"
        @click="To(item.r.id)"
      >
        <div class="left">
          <img :src="item.r.img" alt="" />
        </div>
        <div class="right">
          <div class="n">{{ item.r.n }}</div>
          <span v-if="item.r.recommend_label">{{ item.r.rate }}分 </span>
          <span> {{ item.r.recommend_label }}</span>
          <div class="text">
            <span
              v-for="(value, index) in item.r.recipe_list_tags"
              :key="index"
              >{{ value.text }}</span
            >
          </div>
          <div class="info">
            <img :src="item.r.a.p" alt="" />
            <div class="name">{{ item.r.a.n }}</div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { getkeyword } from "../../api/search";
import Vue from "vue";
import { Sticky } from "vant";

Vue.use(Sticky);
export default {
  data() {
    return {
      key: "",
      keyword: [],
    };
  },
  methods: {
    getkeywordFun() {
      getkeyword({ keyword: this.key }).then((data) => {
        data.result.list.forEach((e) => {
          if (e.type == 13) {
            this.keyword.push(e);
          }
        });
        console.log(this.keyword);
      });
    },
    To(id) {
      this.$router.push({
        path: "/recipe/recipelist",
        query: { id: id },
      });
    },
  },
  created() {
    this.key = this.$route.query.key;
    this.getkeywordFun();
  },
};
</script>

<style lang='less'>
.searchlist {
  .top {
    padding: 0 20px;
    padding-top: 30px;
    padding-bottom: 15px;
    display: flex;
background: white;
    align-items: center;
    .iconfont {
      margin-right: 20px;
      font-weight: bold;
    }
    .ipt {
      position: relative;
      width: 100%;
      input {
        width: 88%;
        background: #f7f7f7;
        height: 33px;
        border: none;
        color: #9d9d9d;
        font-size: 15px;
        padding-left: 35px;
      }
      .icon-sousuo {
        position: absolute;
        left: 12px;
        top: 7px;
        color: #9d9d9d;
        font-size: 18px;
      }
    }
    .cancel {
      font-weight: 12px;
      color: #232323;
      margin-left: 10px;
    }
  }
  .item {
    margin: 0 20px;
    margin-top: 25px;
    .items {
      margin-bottom: 12px;
      display: flex;
      align-items: center;
      .left {
        width: 155px;
        height: 110px;
        border-radius: 10px;
        margin-right: 12px;
        img {
          width: 155px;
          height: 110px;
          border-radius: 5px;
        }
      }

      .right {
        font-size: 12px;
        .n {
          margin-bottom: 10px;
          color: #303030;
          font-weight: bold;
        }
        .text {
          margin-top: 10px;
          span {
            margin-right: 18px;
            color: #666666;
          }
        }
        .info {
          margin-top: 15px;
          display: flex;
          align-items: center;
          img {
            width: 15px;
            height: 15px;
            border-radius: 50%;
            margin-right: 3px;
          }
          .name {
            color: #9f9f9f;
          }
        }
      }
    }
  }
}
</style>